package com.yxy.controller.user;

import com.yxy.common.PageResult;
import com.yxy.common.Result;
import com.yxy.constant.RequestMapperConstant;
import com.yxy.pojo.dto.RemarkDTO;
import com.yxy.pojo.dto.RemarkPageQueryDTO;
import com.yxy.service.RemarkService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController("userRemarkController")
@RequestMapping(RequestMapperConstant.USER_REQUEST_MAPPER + "remark")
@Slf4j
public class RemarkController {

    @Autowired
    private RemarkService remarkService;

    /**
     * 添加评论
     * @param remarkDTO
     * @return
     */
    @PostMapping("/addRemark")
    public Result add(@RequestBody RemarkDTO remarkDTO){
        log.info("添加评论：{}", remarkDTO);
        remarkService.add(remarkDTO);
        return Result.success("评论成功");
    }

    /**
     * 分页查询
     * @param remarkPageQueryDTO
     * @return
     */
    @GetMapping("/getRemarkList")
    public Result<PageResult> page(RemarkPageQueryDTO remarkPageQueryDTO){
        log.info("分页查询评论：{}", remarkPageQueryDTO);
        PageResult result = remarkService.pageQuery(remarkPageQueryDTO);
        return Result.success("", result);
    }

    /**
     * 删除评论
     * @param id
     * @return
     */
    @DeleteMapping("/deleteById")
    public Result deleteById(int id){
        log.info("删除评论：{}", id);
        remarkService.deleteById(id);
        return Result.success("", null);
    }

    /**
     * 赞或踩
     * @param remarkId
     * @param userId
     * @return
     */
    @PutMapping("/thumbs/{remarkId}/{isThumbs}")
    public Result thumbs(@PathVariable int remarkId, @PathVariable int isThumbs){
        log.info("点赞或踩：{}", remarkId);
        remarkService.thumbs(remarkId, isThumbs);
        return Result.success("", null);
    }
}
